﻿using Common.Library.Helper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Clinent.Main.View.SqlServerListen
{
    /// <summary>
    /// UcSqlServerListenManage.xaml 的交互逻辑
    /// </summary>
    public partial class UcSqlServerListenManage
    {
        public UcSqlServerListenManage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlServerProfilerHelper.StartSqlServerProfiler();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string sql = @"INSERT T_Test_Table
                            (
                                Name
                            )
                            VALUES( @Name ) ";
            List<SqlParameter> parameters = new List<SqlParameter>();
            parameters.Add(SqlServerHelper.MakeInParam("@Name", System.Data.SqlDbType.VarChar, 50, $"Test_{DateTime.Now.ToString("yyyyMMddHHmmss")}"));
            SqlConnection sqlConnection = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=Test;User ID=sa;Password=123456;min pool size=1;max pool size=200");
            SqlServerHelper.ExecuteNonQuery(sqlConnection, System.Data.CommandType.Text, sql, parameters.ToArray());

            string sql2 = @"SELECT * FROM T_Test_Table WHERE Id > @Id";
            List<SqlParameter> parameters2 = new List<SqlParameter>();
            parameters2.Add(SqlServerHelper.MakeInParam("@Id", System.Data.SqlDbType.Int, 0, 1));
            SqlServerHelper.ExecuteDataSet(sqlConnection, System.Data.CommandType.Text, sql2, parameters2.ToArray());

            SqlServerHelper.ExecuteDataSet(sqlConnection, System.Data.CommandType.Text, "SELECT * FROM T_Test_Table",null);

            string sql3 = @"UPDATE T_Test_Table SET Name=@Name WHERE Id = @Id";
            List<SqlParameter> parameters3 = new List<SqlParameter>();
            parameters3.Add(SqlServerHelper.MakeInParam("@Id", System.Data.SqlDbType.Int, 0, 1));
            parameters3.Add(SqlServerHelper.MakeInParam("@Name", System.Data.SqlDbType.VarChar, 0, $"Value_{DateTime.Now.ToString("HHmmss")}"));
            SqlServerHelper.ExecuteDataSet(sqlConnection, System.Data.CommandType.Text, sql3, parameters3.ToArray());
        }
    }
}
